<script setup>
import { baseagree, cancellationAccount } from "@/services/user";
import { onLoad, onShow } from "@dcloudio/uni-app";
import { ref } from "vue";

onLoad((e) => {
  code.value = e.code;
});

onShow(() => {
  getList();
});

const code = ref("");
const introData = ref({});

const getList = async () => {
  try {
    // 发送请求
    let res = await baseagree({ code: code.value });
    if (res.code == 200) {
      introData.value = res.data;
    }
  } catch (e) {
    uni.showToast({
      title: e.info,
      icon: "none",
    });
  }
};
const time = ref(3);
const isCountDown = ref(false);
const finushfun = () => {
  isCountDown.value = true;
};
const onChange = (e) => {
  time.value = e.seconds;
};
const showcancellation = ref(false);

const nextfun = () => {
  if (time.value > 0) {
    return;
  }
  showcancellation.value = true;
};

// 注销成功
const cancellation = async () => {
  if (!checked.value) {
    uni.showToast({
      title: "请勾选阅读并同意《注销协议重要提醒》！",
      icon: "none",
    });
    return;
  }
  try {
    let res = await cancellationAccount();
    if (res.code == 200) {
      uni.showToast({
        title: "注销成功",
        icon: "none",
      });
      uni.reLaunch({
        url: "/pages/login/login",
      });
    }
  } catch (e) {
    uni.showToast({
      title: e.info,
      icon: "none",
    });
  }
};
/* 勾选是否阅读权限 */
const checked = ref(false);
const checkboxfun = () => {
  checked.value = !checked.value;
};

const gocancellation = () => {
  uni.navigateTo({
    url: "/pages/mine/userAgreementDeatils?code=cancel_user_agree",
  });
};
</script>
<template>
  <div class="cancellation">
    <text>{{ introData.name }}</text>
    <text class="content-time">{{ introData.create_time }}</text>
    <view class="content-test">
      <up-parse :content="introData.content"></up-parse>
    </view>

    <view class="foodr-bt">
      <view
        class="bt-sbuit"
        @click="nextfun"
        :class="!isCountDown ? 'bt-sbuit-none' : ''"
        ><u-count-down
          :time="15 * 1000"
          format="ss"
          @finish="finushfun"
          @change="onChange"
          ><span v-if="!isCountDown">{{ time + 1 }}秒后</span>
          同意协议</u-count-down
        >
      </view>
    </view>

    <!-- 注销账户 -->
    <view class="password_show">
      <u-popup
        :show="showcancellation"
        mode="center"
        round="10"
        @close="showcancellation = false"
      >
        <view class="productGift">
          <view class="popup-content-title">温馨提示</view>
          <view class="popup-content-item"
            >注销账户无法撤回，请确认注销账户？</view
          >
          <view class="popup-content-item">
            <view class="checkbox">
              <up-checkbox-group>
                <up-checkbox
                  v-model="checked"
                  shape="circle"
                  label="已阅读并同意"
                  activeColor="#01ada8"
                  @change="checkboxfun"
                  labelSize="16px"
                ></up-checkbox>
              </up-checkbox-group>
              <view class="login_urlTitle" @click="gocancellation">
                《注销协议重要提醒》
              </view>
            </view></view
          >
          <view class="popup-content-box">
            <view class="popup-content-bt">
              <view class="popup-content-qx" @click="showcancellation = false"
                >取消</view
              >
              <view class="popup-content-cl" @click="cancellation"
                >确定注销</view
              >
            </view>
          </view>
        </view>
      </u-popup>
    </view>
  </div>
</template>

<style lang="scss" scoped>
@import "index.scss";
</style>
